home *** CD-ROM | disk | FTP | other *** search
Text File | 1990-03-11 | 14.1 KB | 572 lines | [TEXT/MPS ] |
- Program ProjectX;
-
- USES
- Types, { Nothing }
- Errors, { Nothing }
-
- Memory, { Types }
- OSUtils, { Types }
- QuickDraw, { Types }
- Resources, { Types }
- SegLoad, { Types }
-
- Controls, { QuickDraw }
- Events, { QuickDraw }
- Fonts, { QuickDraw }
- Menus, { QuickDraw }
- TextEdit, { QuickDraw }
- ToolUtils, { QuickDraw }
-
- OSEvents, { Types, Events, OSUtils }
- Desk, { Types, QuickDraw, Events }
-
- Windows, { Events, Controls }
- Dialogs, { Windows, TextEdit }
- Devices, { OSUtils, Files, QuickDraw }
- Lists, { Controls }
- Packages, { Dialogs, Files }
- Script; { Packages }
-
- (*
-
- The following lines will rez, compile, link, and execute ProjectX
-
- Rez Types.r SysTypes.r Pict.r ProjectX.rsrc -rd -a -o ProjectX
-
- Pascal ProjectX.p
- Link ProjectX.p.o {PLibraries}PasLib.o {Libraries}Interface.o {Libraries}Runtime.o -o ProjectX
- ProjectX
-
- *)
-
- CONST
- TitleBarHeight = 19;
- ScrollBarWidth = 16;
-
- Lastmenu = 4;
-
- appleMenu = 1;
- AboutItem = 1;
-
- fileMenu = 2;
- QuitItem = 1;
-
- editMenu = 3;
-
- windowMenu = 4;
- ReAdjustItem = 1;
-
- projXwindowKind = 2000;
-
- MainWindowType = 10;
- TitleWindowType = 11;
- GoAwayWindowType = 12;
- ZoomBoxWindowType = 13;
- GrowBoxWindowType = 14;
- VScrollWindowType = 15;
- HScrollWindowType = 16;
-
- VAR
- theEvent : EventRecord;
- theChar : Char;
- tempWindow : WindowPtr;
- Doneflag : Boolean;
- theScreen : Rect;
-
- theItem : Integer;
- theMenu : Integer;
-
- ItemHit : Integer;
- myMenus : Array[1..Lastmenu] of MenuHandle;
- itype : Integer;
- item : Handle;
- box : Rect;
-
- GrowReturn : Longint;
-
- WNEExists : Boolean;
-
- { * Window vars * }
- theMainWindow : WindowPtr;
- theTitleWindow : WindowPtr;
- theGoAwayWindow : WindowPtr;
- theZoomWindow : WindowPtr;
- theGrowWindow : WindowPtr;
- theVScrollWindow : WindowPtr;
- theHScrollWindow : WindowPtr;
-
- MainWindowRect : Rect;
-
- GoAwayBoxWidth : Integer;
- ZoomBoxWidth : Integer;
-
-
- function MyGetNextEvent(evtMask:Integer):Boolean; forward;
-
- {----------------------------------------------------------------------------------}
- Function Str(i:longInt):str255;
-
- var
- myStr : Str255;
-
- begin
- NumToString(i,myStr);
- Str:=myStr;
- end;
- {----------------------------------------------------------------------------------}
- Function Val(s:str255):Longint;
-
- var
- myVal : Longint;
-
- begin
- StringToNum(s,myVal);
- Val:=myVal;
- end;
- {----------------------------------------------------------------------------------}
- function GetScreenBits:Rect;
-
- type
- IntPtr = ^Integer;
-
- var
- WMGRPort : GrafPtr;
-
- begin
- If IntPtr($28E)^=$3FFF then
- GetScreenBits:=GetGDevice^^.gdRect
- else
- begin
- GetWMGRPort(WMGRPort);
- GetScreenBits:=WMGRPort^.portRect;
- end;
- end;
- {------------------------------------------------------------------------------}
- Procedure SetUpMenus;
-
- var
- i : Integer;
-
- begin
- InitMenus;
-
- { * Get and insert menus * }
- for i:=1 to Lastmenu do
- begin
- MyMenus[i]:=GetMenu(i);
- InsertMenu(myMenus[i],0);
- end;
- AddResMenu(MyMenus[appleMenu],'DRVR');
-
- DrawMenuBar;
- end;
- {----------------------------------------------------------------------------------}
- Procedure DoMyUpdate;
-
- var
- TitleOffSet : Integer;
- savePort : GrafPtr;
- thePICT : PicHandle;
- eRect : Rect;
-
- begin
- tempWindow:=WindowPtr(theEvent.message);
- GetPort(savePort);
- SetPort(tempWindow);
- BeginUpdate(tempWindow);
- with windowPeek(tempWindow)^ do
- If windowKind=projXwindowKind then
- begin
- EraseRect(port.portRect);
-
- If dataHandle=handle(TitleWindowType) then
- begin
- with port.portRect do
- begin
- MoveTo(left,top+3);
- LineTo(right,top+3);
-
- MoveTo(left,top+5);
- LineTo(right,top+5);
-
- MoveTo(left,top+7);
- LineTo(right,top+7);
-
- MoveTo(left,top+9);
- LineTo(right,top+9);
-
- MoveTo(left,top+11);
- LineTo(right,top+11);
-
- MoveTo(left,top+13);
- LineTo(right,top+13);
-
- TitleOffSet:=Right Div 2-TitleWidth Div 2;
-
- SetRect(eRect,left+TitleOffSet-3,top,left+TitleOffSet+titleWidth+3,bottom);
- EraseRect(eRect);
-
- MoveTo(left+TitleOffSet,13);
- HLock(handle(titleHandle));
- DrawString(titleHandle^^);
- HunLock(handle(titleHandle));
- end;
- end
- else if (dataHandle=handle(VScrollWindowType)) OR (dataHandle=handle(HScrollWindowType)) then
- DrawControls(tempWindow);
- end;
- EndUpdate(tempWindow);
- SetPort(savePort);
- end;
- {----------------------------------------------------------------------------------}
- Procedure DoAbout;
-
- var
- SavePort : GrafPtr;
- Dialog : DialogPtr;
-
- begin
- GetPort(SavePort);
-
- Dialog:=GetNewDialog(1,Nil,Pointer(-1));
- DrawDialog(Dialog);
-
- Repeat Until MyGetNextEvent(mDownMask+keyDownMask+autoKeyMask);
-
- SetPort(SavePort);
- DisposDialog(Dialog);
- end;
- {----------------------------------------------------------------------------------}
- procedure SizeTheWindow;
-
- begin
- MainWindowRect:=windowPeek(theMainWindow)^.strucRgn^^.RgnBBox;
-
- with MainWindowRect do
- begin
- MoveWindow(theGoAwayWindow,left+1,top-TitleBarHeight+2,false);
- MoveWindow(theTitleWindow,left+GoAwayBoxWidth+1,top-TitleBarHeight+2,false);
- MoveWindow(theZoomWindow,right+ScrollBarWidth-2-ZoomBoxWidth,top-TitleBarHeight+2,false);
- MoveWindow(theVScrollWindow,right,top+1,false);
- MoveWindow(theGrowWindow,right,bottom,false);
- MoveWindow(theHScrollWindow,left+1,bottom,false);
- end;
- end;
- {----------------------------------------------------------------------------------}
- procedure CreateNewWindow;
-
- var
- savePort : GrafPtr;
- thePict : PicHandle;
- bounds : Rect;
- theCTRL : ControlHandle;
-
- begin
- GetPort(savePort);
-
- { * Set up main window * }
- with theScreen do
- SetRect(bounds,left+40,top+50,right-40,bottom-40);
- theMainWindow:=NewWindow(Nil,bounds,'',true,plainDBox,pointer(-1),false,0);
- with windowPeek(theMainWindow)^ do
- begin
- windowKind:=projXwindowKind;
- dataHandle:=handle(MainWindowType);
- end;
-
- { * Make global copy * }
- MainWindowRect:=windowPeek(theMainWindow)^.strucRgn^^.RgnBBox;
-
- { * Set up go away box * }
- thePict:=PicHandle(GetResource('PICT',1002));
- with thePict^^.picFrame do
- SetRect(bounds,0,0,right-left,bottom-top);
- theGoAwayWindow:=NewWindow(Nil,bounds,'',true,plainDBox,pointer(-1),false,0);
- SetWindowPic(theGoAwayWindow,thePict);
- with windowPeek(theGoAwayWindow)^ do
- begin
- windowKind:=projXwindowKind;
- dataHandle:=handle(GoAwayWindowType);
- end;
- with theGoAwayWindow^.portRect do
- GoAwayBoxWidth:=(right-left);
-
- { * Set up zoom box * }
- thePict:=PicHandle(GetResource('PICT',1000));
- with thePict^^.picFrame do
- SetRect(bounds,0,0,right-left,bottom-top);
- theZoomWindow:=NewWindow(Nil,bounds,'',true,plainDBox,pointer(-1),false,0);
- SetWindowPic(theZoomWindow,thePict);
- with windowPeek(theZoomWindow)^ do
- begin
- windowKind:=projXwindowKind;
- dataHandle:=handle(ZoomBoxWindowType);
- end;
- with theZoomWindow^.portRect do
- ZoomBoxWidth:=(right-left);
-
- { * Set up the title window * }
- with MainWindowRect do
- SetRect(bounds,left+GoAwayBoxWidth+1,top-TitleBarHeight+1,right-ZoomBoxWidth+ScrollBarWidth-1,top-1);
- theTitleWindow:=NewWindow(Nil,bounds,'Untitled',true,plainDBox,pointer(-1),false,0);
- with windowPeek(theTitleWindow)^ do
- begin
- windowKind:=projXwindowKind;
- dataHandle:=handle(TitleWindowType);
- end;
- SetPort(theTitleWindow);
- TextFont(SystemFont);
-
- { * Set up grow box * }
- thePict:=PicHandle(GetResource('PICT',1001));
- with thePict^^.picFrame do
- SetRect(bounds,0,0,right-left,bottom-top);
- theGrowWindow:=NewWindow(Nil,bounds,'',true,plainDBox,pointer(-1),false,0);
- SetWindowPic(theGrowWindow,thePict);
- with windowPeek(theGrowWindow)^ do
- begin
- windowKind:=projXwindowKind;
- dataHandle:=handle(GrowBoxWindowType);
- end;
-
- { * Set up the vertical scrollbar window * }
- with MainWindowRect do
- SetRect(bounds,right,top+1,right+ScrollBarWidth-2,bottom-1);
- theVScrollWindow:=NewWindow(Nil,bounds,'',true,plainDBox,pointer(-1),false,0);
- with windowPeek(theVScrollWindow)^ do
- begin
- windowKind:=projXwindowKind;
- dataHandle:=handle(VScrollWindowType);
- end;
- SetPort(theVScrollWindow);
- ValidRect(theVScrollWindow^.portRect);
-
- bounds:=theVScrollWindow^.portRect;
- InsetRect(bounds,-1,-1);
- theCTRL:=NewControl(theVScrollWindow,bounds,'',true,1,1,255,scrollBarProc,0);
-
- { * Set up the horizontal scrollbar window * }
- with MainWindowRect do
- SetRect(bounds,left+1,bottom,right-1,bottom+ScrollBarWidth-2);
- theHScrollWindow:=NewWindow(Nil,bounds,'',true,plainDBox,pointer(-1),false,0);
- with windowPeek(theHScrollWindow)^ do
- begin
- windowKind:=projXwindowKind;
- dataHandle:=handle(HScrollWindowType);
- end;
- SetPort(theHScrollWindow);
- ValidRect(theHScrollWindow^.portRect);
-
- bounds:=theHScrollWindow^.portRect;
- InsetRect(bounds,-1,-1);
- theCTRL:=NewControl(theHScrollWindow,bounds,'',true,1,1,255,scrollBarProc,0);
-
- { * Hilite the title window * }
- HiliteWindow(theTitleWindow,true);
-
- SizeTheWindow;
-
- SetPort(savePort);
- end;
- {----------------------------------------------------------------------------------}
- Procedure DoCommand(mResult:longint);
-
- var
- DArefNum : Integer;
- DAname : Str255;
-
- begin
- theMenu:=HiWrd(mResult);
- theItem:=LoWrd(mResult);
-
- case theMenu of
- appleMenu:
- If theItem=AboutItem then
- DoAbout
- else
- begin
- GetItem(myMenus[appleMenu],theItem,DAname);
- DArefNum:=OpenDeskAcc(DAname);
- end;
- fileMenu:
- If theItem=QuitItem then
- DoneFlag:=true;
- windowMenu:
- Case theItem of
- ReAdjustItem:
- SizeTheWindow;
- end;
- end;{case}
-
- HiliteMenu(0);
- end;
- {----------------------------------------------------------------------------------}
- procedure DragMyWindow(startingPt:Point);
-
- var
- AllWindowsRgn : RgnHandle;
- moveMent : Longint;
- dx,dy : Integer;
-
- begin
- AllWindowsRgn:=NewRgn;
-
- OpenRgn;
-
- FrameRgn(windowPeek(theMainWindow)^.strucRGN);
- FrameRgn(windowPeek(theTitleWindow)^.strucRGN);
- FrameRgn(windowPeek(theGoAwayWindow)^.strucRGN);
- FrameRgn(windowPeek(theZoomWindow)^.strucRGN);
- FrameRgn(windowPeek(theGrowWindow)^.strucRGN);
- FrameRgn(windowPeek(theVScrollWindow)^.strucRGN);
- FrameRgn(windowPeek(theHScrollWindow)^.strucRGN);
-
- CloseRgn(AllWindowsRgn);
-
- moveMent:=DragGrayRgn(AllWindowsRgn,startingPt,theScreen,theScreen,noConstraint,NIL);
-
- If Point(moveMent).h=$8000 then
- dx:=0
- else
- dx:=Point(moveMent).h;
-
- If Point(moveMent).v=$8000 then
- dy:=0
- else
- dy:=Point(moveMent).v;
-
- If (dx<>0) OR (dy<>0) then
- begin
- with windowPeek(theMainWindow)^.strucRGN^^.RgnBBox do
- MoveWindow(theMainWindow,left+dx,top+dy,false);
-
- with windowPeek(theGoAwayWindow)^.strucRGN^^.RgnBBox do
- MoveWindow(theGoAwayWindow,left+dx,top+dy,false);
-
- with windowPeek(theTitleWindow)^.strucRGN^^.RgnBBox do
- MoveWindow(theTitleWindow,left+dx,top+dy,false);
-
- with windowPeek(theZoomWindow)^.strucRGN^^.RgnBBox do
- MoveWindow(theZoomWindow,left+dx,top+dy,false);
-
- with windowPeek(theVScrollWindow)^.strucRGN^^.RgnBBox do
- MoveWindow(theVScrollWindow,left+dx,top+dy,false);
-
- with windowPeek(theGrowWindow)^.strucRGN^^.RgnBBox do
- MoveWindow(theGrowWindow,left+dx,top+dy,false);
-
- with windowPeek(theHScrollWindow)^.strucRGN^^.RgnBBox do
- MoveWindow(theHScrollWindow,left+dx,top+dy,false);
- end;
-
- DisposeRgn(AllWindowsRgn);
- end;
- {----------------------------------------------------------------------------------}
- function CurrentWindowHit(theWindow:WindowPtr):Boolean;
-
- begin
- CurrentWindowHit:=((theWindow<>theMainWindow) | (theWindow<>theTitleWindow)
- | (theWindow<>theGoAwayWindow) | (theWindow<>theZoomWindow)
- | (theWindow<>theGrowWindow) | (theWindow<>theVScrollWindow)
- | (theWindow<>theHScrollWindow));
- end;
- {----------------------------------------------------------------------------------}
- Procedure InitGlob;
-
- const
- UnImplTrapNum = $9F; { * Unimplemented trap * }
- WaitNextEventTrapWord = $60;
-
- var
- theWorld : SysEnvRec;
-
- begin
- { * Get the world, so to speak * }
- If SysEnvirons(1,theWorld)<>envNotPresent then
- WNEExists:=(theWorld.machineType>=0) & (NGetTrapAddress(WaitNextEventTrapWord,ToolTrap)<>NGetTrapAddress(UnImplTrapNum,ToolTrap))
- else
- WNEExists:=false;
-
- theScreen:=GetScreenBits;
-
- CreateNewWindow;
- end;
- {----------------------------------------------------------------------------------}
- function MyGetNextEvent(evtMask:Integer):Boolean;
-
- begin
- If WNEExists then
- MyGetNextEvent:=WaitNextEvent(evtMask,theEvent,6,Nil)
- else
- begin
- SystemTask;
- MyGetNextEvent:=GetNextEvent(evtMask,theEvent);
- end;
- end;
- {----------------------------------------------------------------------------------}
- procedure _DataInit;EXTERNAL;
-
- begin
- { * Get rid of MPW's init code * }
- UnloadSeg(@_DataInit);
-
- FlushEvents(EveryEvent,0);
- InitGraf(@thePort);
- InitFonts;
- TEInit;
- InitWindows;
- InitDialogs(Nil);
- SetUpMenus;
- InitGlob;
-
- Repeat
- InitCursor;
- If MyGetNextEvent(everyEvent) then
- with theEvent do
- case what of
- mouseDown:
- case FindWindow(where,tempWindow) of
- inMenuBar:
- DoCommand(MenuSelect(where));
- InSysWindow:
- SystemClick(theEvent,tempWindow);
- inContent:
- If NOT CurrentWindowHit(tempWindow) then
- SelectWindow(tempWindow)
- else if BAnd(modifiers,cmdKey)<>0 then
- DragWindow(tempWindow,where,GetGrayRGN^^.RGNBBox)
- else if tempWindow=theTitleWindow then
- DragMyWindow(where)
- else if tempWindow=theGrowWindow then
- begin
- GrowReturn:=GrowWindow(theMainWindow,where,GetGrayRGN^^.RGNBBox);
- SizeWindow(theMainWindow,LoWrd(GrowReturn),HiWrd(GrowReturn),true);
- end
- else if tempWindow=theGoAwayWindow then
- begin
-
- end
- else if tempWindow=theZoomWindow then
- begin
-
- end;
- inDrag:
- If NOT CurrentWindowHit(tempWindow) then
- SelectWindow(tempWindow)
- else If BAnd(modifiers,cmdKey)<>0 then
- DragWindow(tempWindow,where,GetGrayRGN^^.RGNBBox);
- end;{case}
- keyDown,autoKey:
- begin
- theChar:=chr(BitAnd(message,255));
- If BitAnd(modifiers,CmdKey)<>0 then
- DoCommand(MenuKey(theChar))
- end;
- updateEvt:
- DoMyUpdate;
- end;
- Until Doneflag;
-
- SetCursor(GetCursor(WatchCursor)^^);
- end.
-